package com.servlet;

import com.bean.Student;
import com.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

@WebServlet("/ServletFind")
public class ServletFind extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        StudentService studentService = new StudentService();
        HashMap<String, Student> hm = studentService.findStudent();
        if (hm.size()==0){
            response.getWriter().write("查无数据,请添加");
            response.setHeader("Refresh","2;URL=entry.jsp");
        }else {
            request.setAttribute("hm",hm);
            request.getRequestDispatcher("find.jsp").forward(request,response);
        }

    }
}
